package com.jdwx.opengl.kotlin2

import java.util.*
import kotlin.Comparator

/**
 * map test
 */
open class pic{

}
interface a{

}
class Box<T>(t: T) {
    var value = t
}
abstract class World{
    val yin = 0
    abstract val ying:Int
}
enum class Color(val rgb: Int) {
    RED(0x1),
    GREEN(0x2),
    BLUE(0x3)
}
class ClassB : a {
//伴生函数
    companion object {
        fun create(): ClassB = ClassB()
        fun get() = "Hi, I am CompanyB" }
}
class ClassC {
    var index = 0
    fun get(index: Int): Int {
        return 0
    }
    companion object CompanyC {
        fun create(): ClassC = ClassC()
        fun get() = "Hi, I am CompanyC"
    } }
data class User(
        val name: String,
        val gender: String,
        val age: Int
){
    fun validate(): Boolean {
        return this.age>26

    }

}

fun main(){
    val jack = User("Jack", "Male", 1)
    jack.validate()
    ClassB.Companion.create()
    var box = Box(0)
    box.value

    val list = listOf(1,2,3,4,5,6,7)
    var map = list.map({it})
    var mapc = list.map({it*it})
    println( mapc )
    var mapadd = list.map({it+10})
    println( mapadd )
    val programmer = listOf("K&R" to "C", "Bjar" to "C++", "Linus" to "C", "James" to " Java")
    println( programmer )
    var l = programmer[0]
    val s = setOf<Int>(1)
    var s1 = s.plus(setOf<Int>(3,4))
    println( s1 )
    val hs = hashSetOf(1,3,2,7)
    println( hs )
    val map1 = mapOf(1 to "x", 2 to "y", 3 to "z")
    print( map1.get(1))
    val map2 = mapOf("1" to "x", "2" to "y", "3" to "z")
    print( map2.get("1"))

    //map2.getOrDefault("pp",0)
    val red = Color.BLUE
    print(red.rgb)
    fun countCompare() {
        var list = mutableListOf(1, 4, 3, 7, 11, 9, 10, 20)
        var countCompare = 0
        Collections.sort(list, object : Comparator<Int> {
            override fun compare(o1: Int, o2: Int): Int {
                countCompare++
                println("countCompare=$countCompare")
                println(list)
                return o1.compareTo(o2)
            } })
    }
    countCompare()
}

